/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wargame.controller;

import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import wargame.entity.*;
import module.*;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Clarence
 */
@Controller
@RequestMapping(value = "/bid")
public class BidController {

    /*
     *
     * DEPRECEATED!!!
     * MOVED TO PROJECT CONTROLLER
     *
     */
    @RequestMapping(value = "/bidProject.do", method = RequestMethod.POST)
    public ModelAndView bidProject(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value="project_id") int project_id,
            @RequestParam(value="parent_id", required=false) int parent_id, Model model) {

        ModelAndView mv = new ModelAndView();

        if(GameTurn.game_pause){
            mv.setViewName("redirect:/servlet/project/bidProjects");
            mv.addObject("announcement", "game is paused. no actions is allowed");
            return mv;
        }

        Player p = ManagePlayer.getThisPlayer(request);
        
        int project_bid = Integer.parseInt(request.getParameter(Integer.toString(project_id)));

        String announcement;
        String status =ManageBid.addABid(p.getPlayer_id(), project_id, project_bid);
        if(status.equals("success")){
            announcement = "successfully submitted bid for the project #" + project_id;
        } else{
            announcement = "fails to submit bid for project #" + project_id;
        }

        mv.addObject("announcement", announcement);
        mv.setViewName("bid_project");
        
        return mv;
    }
}
